package com.example.yuejian.yuejian.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.activity.ShowPhotoDetailActivity;
import com.example.yuejian.yuejian.bean.ShowPhotoList;
import com.example.yuejian.yuejian.view.RoundImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/9/18.
 */

public class MyShowPhotoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
    private Context mContext;;
    private List mDataList;
   //private List<ShowPhotoList> list;
    public LayoutInflater mLayoutInflater;
    public MyShowPhotoAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
   /*public void setList(List<ShowPhotoList> list)
    {
        this.list=list;
    }*/

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_myshowphoto_list, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ShowPhotoList entity = (ShowPhotoList) mDataList.get(position);
        if (null == entity)
            return;
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.myshow_username.setText(entity.getUsername());
        viewHolder.myshow_time.setText(entity.getCreatetime());
        viewHolder.myshow_content.setText(entity.getTitle());



        if (!"".equals(entity.getUserphoto()))
        {
            Picasso.with(mContext).load(entity.getUserphoto()).into(viewHolder.myshow_userimage);
        }
        else
        {
            viewHolder.myshow_userimage.setImageResource(R.drawable.camera);
        }
        if (!"".equals(entity.getPhoto()))
        {
            Picasso.with(mContext).load(entity.getPhoto()).into(viewHolder.myshow_image);
        }

        viewHolder.myshow_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, ShowPhotoDetailActivity.class);
                intent.putExtra("showphoto_id",entity.getId()+"");
                mContext.startActivity(intent);

            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView myshow_username;
        RoundImageView myshow_userimage;
         TextView myshow_time;
        TextView myshow_content;
        ImageView myshow_image;
       LinearLayout myshow_detail;

        public ViewHolder(View itemView) {
            super(itemView);
            myshow_username=(TextView)itemView.findViewById(R.id.myshowphoto_list_username);
            myshow_content = (TextView) itemView.findViewById(R.id.myshowphoto_list_contet);
            myshow_time = (TextView) itemView.findViewById(R.id.myshowphoto_list_time);
            myshow_userimage = (RoundImageView) itemView.findViewById(R.id.myshowphoto_list_user_image);
            myshow_image=(ImageView)itemView.findViewById(R.id.myshowphoto_list_image_content) ;
            myshow_detail=(LinearLayout)itemView.findViewById(R.id.myshowphoto_list_detail);

        }
    }

}
